import { testLoginApi } from '@/api/login'
import { useMemberStore } from '@/stores'
import type { loginResult } from '@/types/member'

export const testLogin = () => {
  testLoginApi('13312345678').then((res) => {
    loginSuccess(res.result)
  })
}

export const loginSuccess = (userData: loginResult) => {
  if (Object.keys(userData).length === 0) {
    uni.showToast({
      icon: 'error',
      title: '登录失败',
    })
    return
  }
  useMemberStore().setProfile(userData)
  uni.showToast({
    icon: 'success',
    title: '登录成功',
  })
  setTimeout(() => {
    uni.$emit('refreshData')
    uni.navigateBack()
  }, 500)
}
